/* 
 * File:   File.cpp
 * Author: guilhermemg
 * 
 * Created on 12 de Fevereiro de 2012, 15:09
 */

#include "File.h"

File::File(string p) {
    setPath(p);
}

File::File(const File& orig) {
}

File::~File() {
}

int File::writeLine(string line) {
    try {
        file.open(path.c_str(), ios::app | ios::out);
        file << line.append("\n");
        file.close();
    }
    catch(...) {
        cerr << "Unable to open file. Method: writeLine" << endl;
    }
    return 0;
}

vector<string> File::readLines() {
  vector<string> lines;

  try {
      file.open(path.c_str(), ios::in);

      string line;
      if (file.is_open())
      {
        while ( file.good() )
        {
          getline (file, line);
          lines.push_back(line);
        }
        file.close();
      }
  }
  catch(...) {
      cerr << "Unable to open file. Method: readLines" << endl;
  }
  return lines;
}

void File::setPath(string p) {
    this->path = p;
}